package com.bawei.module_mine.model.service

import com.bawei.lib_net.RetrofitFactory
import com.bawei.lib_net.entity.ResponseEntity
import com.bawei.module_mine.model.api.LoginApi
import com.bawei.module_mine.model.entity.UserEntity
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

interface QuickLoginApi {
    @FormUrlEncoded
    @POST("/user/quickLoginJG")
    suspend fun quickLoginJG(
        @Field("exID") exID: String,
        @Field("loginToken") loginToken: String
    ): ResponseEntity<UserEntity>
}

class UserCenterService {
    suspend fun login(username:String,password:String):ResponseEntity<UserEntity>{
        val api= RetrofitFactory.getRetrofitFactory().create<LoginApi>(LoginApi::class.java)
        return api.login(username = username, password = password)
    }
    suspend fun register(username:String,password:String):ResponseEntity<UserEntity>{
        val api= RetrofitFactory.getRetrofitFactory().create<LoginApi>(LoginApi::class.java)
        return api.register(username = username, password = password)
    }
    
    /**
     * 一键登录
     */
//    suspend fun quickLogin(phoneNumber: String): ResponseEntity<UserEntity> {
//        val api = RetrofitFactory.getRetrofitFactory().create<LoginApi>(LoginApi::class.java)
//        return api.quickLogin(phoneNumber = phoneNumber)
//    }

    private val api = RetrofitFactory.getRetrofitFactory().create(QuickLoginApi::class.java)
    suspend fun quickLoginJG(loginToken: String, exID: String): ResponseEntity<UserEntity> {
        return api.quickLoginJG(exID, loginToken)
    }
}